// src/main/ipc/fileHandlers.ts
import { ipcMain } from 'electron' // 导入 dialog 模块
import GlobalWinApi from './api/globalWin.api'
import FileOperationApi from './api/fileOperation.api'
import { IpcKeys } from '../../common/enums/ipc.enum'
import { registerTerminalIpc } from './ipc/terminal.ipc'
import { registerScreenRecordingIpc } from './ipc/screenRecording.ipc'
import { registerMockIpc } from './ipc/mock.ipc'
export function registerIpcHandlers() {
  // 1. 处理文件保存对话框
  ipcMain.handle(IpcKeys.SHOW_SAVE_DIALOG, (_) => {
    return FileOperationApi.showSaveDialog()
  })

  // 2. 处理文件写入（保持不变）
  ipcMain.handle(IpcKeys.WRITE_FILE, (_, filePath: string, content: any) => {
    return FileOperationApi.writeFile(filePath, content)
  })
  // 3. 处理获取所有文件
  ipcMain.handle(IpcKeys.GET_ALL_FILES, (_, filePath: string) => {
    return FileOperationApi.getAllFiles(filePath)
  })
  // 3. 处理文件读取（保持不变）
  ipcMain.handle(IpcKeys.GET_FILE_CONTENT, (_, filePath: string) => {
    return FileOperationApi.getFileContent(filePath)
  })
  /**
   * 3. 退出应用
   */
  ipcMain.handle(IpcKeys.CLOSE_APP_EVENT, (_event) => {
    GlobalWinApi.closeApp()
  })
  registerTerminalIpc()
  registerScreenRecordingIpc()
  registerMockIpc()
}
